package asia.lics.web.controller.system;


import asia.lics.common.annotation.Log;
import asia.lics.common.core.controller.BaseController;
import asia.lics.common.core.domain.AjaxResult;
import asia.lics.common.core.page.TableDataInfo;
import asia.lics.common.enums.BusinessType;
import asia.lics.common.utils.poi.ExcelUtil;
import asia.lics.system.domain.FSubject;
import asia.lics.system.service.IFSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科目Controller
 *
 * @author ss-tutor
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/system/subject")
public class FSubjectController extends BaseController {
    @Autowired
    private IFSubjectService fSubjectService;

    /**
     * 查询科目列表
     */
    @PreAuthorize("@ss.hasPermi('system:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(FSubject fSubject) {
        startPage();
        List<FSubject> list = fSubjectService.selectFSubjectList(fSubject);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:subject:list')")
    @GetMapping("/tree")
    public AjaxResult tree(String name) {
        return AjaxResult.success(fSubjectService.selectFSubjectTree(name));
    }

    /**
     * 导出科目列表
     */
    @PreAuthorize("@ss.hasPermi('system:subject:export')")
    @Log(title = "科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FSubject fSubject) {
        List<FSubject> list = fSubjectService.selectFSubjectList(fSubject);
        ExcelUtil<FSubject> util = new ExcelUtil<FSubject>(FSubject.class);
        util.exportExcel(response, list, "科目数据");
    }

    /**
     * 获取科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fSubjectService.selectFSubjectById(id));
    }

    /**
     * 新增科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:add')")
    @Log(title = "科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FSubject fSubject) {
        return toAjax(fSubjectService.insertFSubject(fSubject));
    }

    /**
     * 修改科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:edit')")
    @Log(title = "科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FSubject fSubject) {
        return toAjax(fSubjectService.updateFSubject(fSubject));
    }

    /**
     * 删除科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:remove')")
    @Log(title = "科目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fSubjectService.deleteFSubjectByIds(ids));
    }
}
